The invention relates to computer graphics. More particularly, it relates to rendering a computer image.
Computer graphics systems are used to render all kinds of objects for display. In general, it is important that objects rendered for display appear as realistic to a viewer as possible. This is particularly the case, for example, in computer graphics imagery (CGI) for use in motion pictures and animation. As would be known to a person skilled in the relevant art, realistic scenes are typically rendered using complex, programable shading.
Complex shading involves the use of a special programming language known in the relevant art as a shading language. A shading language is used to specify the appearance and surface characteristics of objects in an image or a scene. See Pat Hanrahan and Jim Lawson, xe2x80x9cA language for Shading and Lighting Calculations,xe2x80x9d in Computer Graphics (SIGGRAPH ""90 Proceedings) Vol. 24, pp. 289-94, which is herein incorporated by reference in its entirety, for a description of a shading language. A typical shading language can simulate a wide variety of appearances including, for example, wood, metal, plastic, fabric, glass, hair, skin, et cetera. A shading language can also be used to describe the emission characteristics of light sources in a scene, the color and reflective properties of each object in a scene, and the transmittance properties of atmospheric media. In many CGI applications, the appearance and surface characteristics of every object in a scene are described using a shading language. As would be known to a person skilled in the relevant art, programmable shading plays an important role in the creation of special effects for movies and television. Programmable shading also plays an important role in other applications as well, for example, in engineering and scientific applications for visualization of data.
A typical software application program accesses shading language procedures through a programmable interface extension of a graphics application programming interface (graphics API). As would be known to a person skilled in the relevant art, a shading language is basically a library of procedures, known in the relevant art as shaders, that can be called during the rendering of an image. A shading language procedure can have very general programming constructs such as loops, conditional statements, and functions. In some examples, shading language source files (i.e., procedures) are compiled to produce object files. When a scene description using a shading language is being rendered, an object file corresponding to a shader must be retrieved from a library and loaded into the memory of the computer graphics system being used to render the scene. The object file must then be executed by the graphics system""s general purpose processor in order to produce the desired effects in the rendered scene.
In many applications, it is important that the computer graphics system used to render objects for display operate at an interactive rate. The known methods used to implement complex shading language procedures place a significant burden on the graphics hardware and driver software of computer graphics systems. For example, graphics hardware is generally designed to support a parametric appearance model. Phong lighting is evaluated per vertex with one or more texture maps applied after Gouraud interpolation of the lighting results. Therefore, known complex shading language procedures are typically translated into a general purpose programming language and compiled to run on a general purpose processor. Because general purpose processors are not designed to process millions of pixels each second, as are special purpose graphics processors and graphics hardware, the known methods used to implement complex shading language procedures cannot be implemented at an interactive rate on most, if not all, available computer graphic systems.
Simple shading capabilities are supported, for example, by the NVIDIA GEFORCE3 and ATI RADEON 8500 graphics systems. These shading capabilities are generally in the form of straight-line sections of assembly code, which do not support branching or looping. These graphic systems do not support complex shading.
What is needed are new techniques for implementing shading procedures at an interactive rate in computer graphics systems.
The present invention provides a system, method, and computer program product for real-time shading of computer generated images. A level of detail shading function is produced and stored in a computer readable memory. During the rendering of an object, input parameters are provided to the level of detail shading function. These input parameters are associated with one or more blocks of code in the level of detail shading function. The input parameters specify how an object is to be shaded using the level of detail shading function.
In an embodiment of the invention, a level of detail shading function is produced using computer program logic that controls the operation of a processor. The computer program logic is implemented using a computer or host system having at least one processor. Under the control of the computer program logic, the host system receives a shading function. The received shading function includes computer code. The shading function can be received, for example, by reading the shading function from a computer readable medium or a memory.
Under the control of the computer program logic, the host system analyzes the code of the shading function to identify at least one candidate block of code in the shading function that can be simplified. After the candidate block of code is identified, simplified blocks of code are generated that can be used in lieu of the candidate block of code during the rendering of an object. Candidate blocks of code that can be identified by embodiments of the invention include, for example, candidate surface texture blocks of code, candidate surface reflectance blocks of code, candidate surface color blocks of code, and/or candidate object transformation blocks of code. According to the invention, a simplified block of code includes, for example, a block of code that requires less time to execute than an associated candidate block of code, a block of code that requires less hardware to execute than an associated candidate block of code, a block of code that requires fewer textures to execute than an associated candidate block of code, and/or a block of code that requires fewer passes through a rendering pipeline to execute than an associated candidate block.
Under the control of the computer program logic, the host system associates each candidate block of code and each simplified block of code with at least one input parameter. According to the invention, an input parameter can be, for example, a parameter relating to rendering time, a parameter relating to distance between a computer modeled object and a computer modeled eye, a parameter relating to screen size of an object, and/or a parameter relating to angular position of an object relative to a computer modeled eye. Input parameters may be associated with a single block of code or with multiple blocks of code. A particular block of code can be associated with a single input parameter or multiple input parameters. Candidate blocks of code and simplified blocks of code are assembled into a level of detail shading function and stored in a computer readable medium.
In embodiments of the invention, at least one level of detail shading function stored in a computer readable medium is used to shade computer generated images in real-time. In these embodiments, the state of the at least one input parameter is specified, for example, by an application program variable, and used to determine how an object is to be shaded during rendering. In accordance with the invention, the specified input parameter is used to select at least one block of code from the level of detail shading function. This at least one block of code is then used in shading a rendered object.
It is an advantage of the present invention that embodiments can be implemented using one or more passes through the graphics pipelines of commercially available graphics accelerator cards.